<template>
  <!-- 查询预约 -->
  <div>
    <TopFilter
      :list="topFilterList"
      :cols="3"
      labelWidth="80"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      height="auto"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn='false'
      :onColumnsChange="columns => this.columns = columns"
    ></FilterTable>
      <!-- :onRowSelectChange="selectChangeHandle" -->
    <!-- <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button @click="closeDialog">返 回</el-button>
      <el-button @click="saveDialog" type="primary">确 定</el-button>
    </div> -->
  </div>
</template>

<script>
import {
  appointmentTestDrive,    // 预约试驾分页列表
  detailDriveManagement,
} from '@/api/potenCus/customer/driveManagement';
import { dictionary } from '@/utils/dictMixin';
import { phone, VIN, formatDat, IDCard } from '@/utils/validate';
export default {
  name: 'checkInfo',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'check'
    },
    rowData: {
      type: Object,
      default: () => ({})
    },
    RolePosition:{
      type: Array,
      default: () => ([])
    }
  },
  data() {
    return {
      topFilterList: this.createTopFilters(),
      fetchParams: {},
      dialogTitle: '',
      fetchApi: appointmentTestDrive,
      columns: this.createTableColumns(),
      handleType: '',
      // visible: false,
      // formData: {},
      conf: { search: '' },
      selectedRow: null,
      length: '',
      total: '',
      // isDis: false
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      console.log('rowData', this.rowData, this.type)
      this.total = this.rowData.total
      if(this.type === 'check'){
        // if(this.rowData.records){
        //   this.rowData.records.forEach(x =>{
        //     console.log('x.invitationsDate',x.invitationsDate)
        //     // var date = new Date();
        //     // var year = date.getFullYear();
        //     // var month = date.getMonth() + 1;
        //     // var day = date.getDate();
        //     // var nowDate = year + '-' + month + '-' + day;
        //     // console.log('nowDate', nowDate)

        //     let curDate = formatDat(new Date().getTime())
        //     let invitaDate = formatDat(x.invitationsDate)
        //     console.log('当天/预约', curDate, invitaDate)
        //     console.log('当天1/预约1', Date.parse(curDate) === Date.parse(invitaDate) )
        //     if( Date.parse(curDate) === Date.parse(invitaDate) ){
        //       this.isDis = false
        //     } else{
        //       this.isDis = true
        //     }
        //   })
        // }
      }
      // if (this.type === 'edit' || this.type === 'show' || this.type === 'check') {
      //   // 更新接口需要的记录 ID
      //   this.recordId = this.rowData.basedataId;
      //   this.formList.forEach(x => {
      //     x.initialValue = this.rowData[x.fieldName];
      //   });
      // }
    },
    isToday(str) {
      return new Date().getTime() - new Date(str).getTime() < 86400000;
    },
    // selectChangeHandle(rows) {
    //   if (!rows.length) return;
    //   this.selectedRow = rows[0];
    // },
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          labelWidth: '0',
          render: () =>{
            return (<div>{`当前待处理试驾/乘预约${this.total}人`}</div>)
          }
        },
        {
          type: 'INPUT',
          label: '客户手机号',
          fieldName: 'potentialCustomerPhone',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'potentialCustomerName',
          placeholder: '请输入'
        },
      ];
    },
    createTableColumns() {
      // console.log('table的rowData',this.rowData)
      //   if(this.rowData.records){
      //     let curDate = formatDat(new Date().getTime())
      //     let curDate1 = Date.parse(curDate)
      //     console.log('当天日期', curDate, curDate1)
      //     this.rowData.records.forEach(x =>{
      //       console.log('x.invitationsDate',x.invitationsDate)
      //       let invitaDate = formatDat(x.invitationsDate)
      //       // let invitaDate1 = Date.parse(invitaDate)
      //       console.log('预约日期xxxxx', invitaDate,curDate, curDate==invitaDate )
      //       if(invitaDate === curDate ){
      //         this.isDis = false
      //       } else{
      //         this.isDis = true
      //       }
      //     })
      //   }

      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 110,
          fixed: 'right',
          render: (props, h) => {
            let curDate = formatDat(new Date().getTime())
            let curDate1 = Date.parse(curDate)
            let invitaDate = formatDat(props.row.invitationsDate)
            let invitaDate1 = Date.parse(invitaDate)
            console.log('日期', curDate, invitaDate )
            console.log('时间戳', curDate1, invitaDate1, invitaDate1<curDate1)
            return (
              <div>
                <el-button size="mini" type="text"  onClick={() => this.startDrive(props.row)} disabled={invitaDate1<curDate1? true: false}>
                  开始试驾/乘
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 60,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '预约日期',
          dataIndex: 'invitationsDate',
          width: 150,
          align: 'center',
          render: props =>{
            return <span>{ formatDat(props.row.invitationsDate) } </span>
          }
        },
        // {
        //   title: '预约时段',
        //   dataIndex: 'period',
        //   width: 150,
        //   align: 'center',
        //   // render: props =>{
        //   //   return <span>{ formatDates(props.row.driveSAt) } </span>
        //   // }
        // },
        {
          title: '意向类型',
          dataIndex: 'driveType',
          width: 150,
          align: 'center',
          filterType: 'checkbox',
          filterItems: this.createDictList('2026'),
          render: props => {
            return <span>{this.createDictText(props.row.driveType, '2026')}</span>;
          }
        },
        {
          title: '意向车型',
          dataIndex: 'intentCar',
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'potentialCustomerName',
          filterType: 'input'
        },
        {
          title: '客户手机号',
          dataIndex: 'potentialCustomerPhone',
          filterType: 'input'
        },
        {
          title: '试驾人姓名',
          dataIndex: 'customerName',
          filterType: 'input'
        },
        {
          title: '试驾人手机号',
          dataIndex: 'mobile',
          filterType: 'input'
        },
        {
          title: '展厅顾问',
          dataIndex: 'employeeName',
          filterType: 'input'
        },
        {
          title: '试驾路线',
          dataIndex: 'wayName',
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          filterType: 'input'
        },
      ];
    },
    async startDrive(row){
      console.log('预约试驾')
      const res = await detailDriveManagement(row.itemId);
      console.log('预约试驾明细', res);
      if (res.resultCode === 200) {
        this.$emit('fatherClose', res);
      }
    },
    saveDialog() {
      this.closeDialog(this.selectedRow);
    },
    closeDialog(data) {
      this.$emit('close', false, data);
    },
    // showHandler() {
    //   this.dialogTitle = `${this.conf[this.handleType]}`;
    //   this.visible = true;
    // },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // closeHandler(val, type) {
    //   this.visible = val;
    //   if (type === 'refresh') {
    //     // 重新加载
    //     this.fetchParams = { ...this.fetchParams };
    //   }
    // }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  }
};
</script>

<style lang="less" scoped>
</style>
